package yxy.game.pm2.command.therionHunting;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.TherionHuntingMessage;
import yxy.game.pm2.module.therionHunting.TherionHandle;
import yxy.game.pm2.module.therionHunting.TherionModelInfo;
import yxy.game.pm2.module.therionHunting.TherionModule;

import java.util.ArrayList;

/**
 * @name CMD_TherionPlayModeChoose
 * @author wrs
 * @descrition 神兽玩法模式选择
 * @since 2022-06-13
 */
@MessageType(proto = Command.TherionPlayModeChoose ,classtype = TherionHuntingMessage.TherionPlayModeChooseRequest.class)
public class CMD_TherionPlayModeChoose extends Command<TherionHuntingMessage.TherionPlayModeChooseRequest> {

    @Override
    public void execute(MessageSource messageSource, TherionHuntingMessage.TherionPlayModeChooseRequest request) throws Exception {

        TherionHuntingMessage.TherionPlayModeChooseResponse.Builder response = TherionHuntingMessage.TherionPlayModeChooseResponse.newBuilder();

        try {
            TherionModelInfo local = TherionModelInfo.get(TherionModule.THERION_LOCAL); //本服
            TherionModelInfo cross = TherionModelInfo.get(TherionModule.THERION_CROSS); //跨服
            TherionModelInfo world = TherionModelInfo.get(TherionModule.THERION_WORLD); //世界

            if (local == null || cross == null || world == null){
                send(messageSource,response, Result.DataError);
                return;
            }

            ArrayList<TherionModelInfo> modelInfos = new ArrayList<>();
            modelInfos.add(local);
            modelInfos.add(cross);
            modelInfos.add(world);

            //模式信息封装
            Result result = new TherionHandle().packModelInfo(modelInfos,response);

            send(messageSource,response,result);

        }catch (Exception e){
            e.printStackTrace();
            send(messageSource,response, Result.DataError);
        }
    }

    private void send(MessageSource messageSource, TherionHuntingMessage.TherionPlayModeChooseResponse.Builder response, Result result) {
        response.setResult(result.packResult());
        MessageEmitterHandler.getInstance().send(messageSource, response.build());
    }
}
